define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xiservice/benfit/index' + location.search,
                    add_url: 'xiservice/benfit/add',
                    edit_url: 'xiservice/benfit/edit',
                    del_url: 'xiservice/benfit/del',
                    multi_url: 'xiservice/benfit/multi',
                    import_url: 'xiservice/benfit/import',
                    table: 'xiservice_user_benfit',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,     
                showExport: false,
                showToggle: false,
                showColumns: false,                
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        {field: 'service_info.name', title: __('服务名称'), operate: false},
                        {field: 'order.name', title: __('下单用户'), operate:false, formatter: function (val,row) {
                              var html='';
                              html += '<div style="text-align:left">'+row.order.name+'</div>';
                              html += '<div style="text-align:left">'+row.order.phone+'</div>';
                             return html;
                        }}, 
                        {field: 'money', title: __('Money'), operate:false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
